"""
pip install playwright
from langchain_community.agent_toolkits import PlayWrightBrowserToolkit

from langchain_community.tools.playwright.utils import (
    create_async_playwright_browser,  # A synchronous browser is available, though it isn't compatible with jupyter.\n",	  },
)
async_browser = create_async_playwright_browser()
toolkit = PlayWrightBrowserToolkit.from_browser(async_browser=async_browser)
tools = toolkit.get_tools()
#print(tools)
tools_by_name = {tool.name: tool for tool in tools}
#print(tools_by_name)

async def use(query):
    navigate_tool = tools_by_name["navigate_browser"]
    if navigate_tool:
        await navigate_tool.arun({"url": "http://www.cqu.edu.cn"})
use("")
"""
"""
tools_by_name = {tool.name: tool for tool in tools}
navigate_tool = tools_by_name["navigate_browser"]yy
get_elements_tool = tools_by_name["get_elements"]
navigate_tool.run(
    {"url": "http://www.cqu.edu.cn"}
)
"""
"""
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    #for browser_type in [p.chromium, p.firefox, p.webkit]:
    for browser_type in [p.chromium]:
        browser = browser_type.launch()
        page = browser.new_page()
        page.goto('https://baidu.com/')
        page.screenshot(path=f'example-{browser_type.name}.png')
        browser.close()
"""
import asyncio
from playwright.async_api import async_playwright

async def main():
    async with async_playwright() as p:
        for browser_type in [p.chromium]:
            browser = await browser_type.launch()
            page = await browser.new_page()
            await page.goto('http://baidu.com/')
            await page.screenshot(path=f'example2-{browser_type.name}.png')
            await browser.close()

asyncio.get_event_loop().run_until_complete(main())
print("OK and wait....")